package cn.lixufeng.order.controller;

import cn.lixufeng.basic.utils.AjaxResult;
import cn.lixufeng.basic.utils.LoginContext;
import cn.lixufeng.basic.utils.PageList;
import cn.lixufeng.order.domain.AdoptOrder;
import cn.lixufeng.order.query.AdoptOrderQuery;
import cn.lixufeng.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 领养adopt
 */
@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 提交订单
     * @param params
     * @param request
     * @return
     */
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            // 返回支付数据，支付单要用
            String payData = adoptOrderService.submit(params, LoginContext.currentLoginInfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("提交订单失败！");
        }

    }

    // 平台员工和店铺员工
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.admin(query,LoginContext.currentLoginInfo(request));
    }

    // 用户订单
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.user(query,LoginContext.currentLoginInfo(request));
    }

    // 感觉id获取订单详情
    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id){
        return adoptOrderService.findById(id);
    }
}
